//
//  AppService.m
//  TestOCRedux
//
//  Created by Hotacool on 2019/2/26.
//  Copyright © 2019 Hotacool. All rights reserved.
//

#import "AppService.h"

@implementation AppService {
    dispatch_source_t _timer;
}

+ (instancetype)shareInstance {
    static AppService *instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [AppService new];
    });
    return instance;
}

- (void)requestAutoEatWithBlock:(AutoEatBlock)block {
    _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue());
    dispatch_source_set_timer(_timer, DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC, 0 * NSEC_PER_SEC);
    dispatch_source_set_event_handler(_timer, ^{
        block(1);
    });
    dispatch_resume(_timer);
}

- (void)clear {
    if (_timer) {
        dispatch_cancel(_timer);
        _timer = nil;
    }
}
@end
